<?php

/**
 * This is the model class for table "{{stockitem}}".
 *
 * The followings are the available columns in table '{{stockitem}}':
 * @property string $idstockitem
 * @property string $itemname
 * @property string $idmeasureunit
 * @property string $idstockgroup
 * @property string $itemquantity
 * @property string $itemrateper
 * @property string $itemtotalvalue
 *
 * The followings are the available model relations:
 * @property Demand[] $demands
 * @property Distribution[] $distributions
 * @property Measureunit $idmeasureunit0
 * @property Stockgroup $idstockgroup0
 * @property Stocktransfer[] $stocktransfers
 */
class Stockitem extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Stockitem the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{stockitem}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('itemname, idmeasureunit, idstockgroup, itemquantity', 'required'),
			array('itemname', 'length', 'max'=>45),
			array('idmeasureunit, idstockgroup, itemquantity, itemrateper, itemtotalvalue', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idstockitem, itemname, idmeasureunit, idstockgroup, itemquantity, itemrateper, itemtotalvalue', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'demands' => array(self::HAS_MANY, 'Demand', 'idstockitem'),
			'distributions' => array(self::HAS_MANY, 'Distribution', 'idstockitem'),
			'idmeasureunit0' => array(self::BELONGS_TO, 'Measureunit', 'idmeasureunit'),
			'idstockgroup0' => array(self::BELONGS_TO, 'Stockgroup', 'idstockgroup'),
			'stocktransfers' => array(self::HAS_MANY, 'Stocktransfer', 'idstockitem'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idstockitem' => 'Idstockitem',
			'itemname' => 'Itemname',
			'idmeasureunit' => 'Idmeasureunit',
			'idstockgroup' => 'Idstockgroup',
			'itemquantity' => 'Itemquantity',
			'itemrateper' => 'Itemrateper',
			'itemtotalvalue' => 'Itemtotalvalue',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idstockitem',$this->idstockitem,true);
		$criteria->compare('itemname',$this->itemname,true);
		$criteria->compare('idmeasureunit',$this->idmeasureunit,true);
		$criteria->compare('idstockgroup',$this->idstockgroup,true);
		$criteria->compare('itemquantity',$this->itemquantity,true);
		$criteria->compare('itemrateper',$this->itemrateper,true);
		$criteria->compare('itemtotalvalue',$this->itemtotalvalue,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}